{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'indices'|trans }} - {{ index.name }} - {{ 'search'|trans }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'indices'|trans, 'link': {'url': path('indices')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': index.name, 'badge': {'title': index.health|trans, 'context': index.health}}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/index/index_read_tabs.html.twig' with {'active': 'search'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.form({'form': form, 'type': 'search'}) }}
        {% endblock %}
    {% endembed %}

    {% if documents is defined %}
        {% embed 'Embed/block_embed.html.twig' %}
            {% import 'Import/app_import.html.twig' as appImport %}
            {% block content %}
                {{ appImport.heading({'level': 3, 'title': 'documents'|trans, 'badge': {'title': documents.total}}) }}

                {% if 0 < documents.total %}
                    {% if is_granted('INDEX_EXPORT', index) %}
                        {% embed 'Embed/buttons_embed.html.twig' %}
                            {% block content %}
                                <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'csv', 'delimiter': ','}|merge(app.request.query.all)) }}">CSV,</a>
                                <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'csv', 'delimiter': ';'}|merge(app.request.query.all)) }}">CSV;</a>
                                <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'csv', 'delimiter': '\t'}|merge(app.request.query.all)) }}">TSV</a>
                                <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'ods'}|merge(app.request.query.all)) }}">ODS</a>
                                <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'xlsx'}|merge(app.request.query.all)) }}">XLSX</a>
                                {% if true == index.hasMappingType('geo_point') or true == index.hasMappingType('geo_shape') %}
                                    <a class="btn btn-primary btn-sm" href="{{ path('indices_read_export', {'index': index.name, 'type': 'geojson'}|merge(app.request.query.all)) }}">GEOJSON</a>
                                {% endif %}
                            {% endblock %}
                        {% endembed %}
                    {% endif %}

                    {{ appImport.paginator(documents) }}

                    {% include 'Modules/index/index_read_search_list.html.twig' with {'documents': documents} %}

                    {{ appImport.paginator(documents) }}
                {% endif %}
            {% endblock %}
        {% endembed %}
    {% endif %}
{% endblock %}

{% block scripts %}
    {{ parent() }}

    <script type="text/javascript">
        var form = document.querySelector('form');
        var page = document.getElementById('page');

        form.addEventListener('submit', function(event) {
            page.value = 1;
        });
    </script>
{% endblock %}
